SQL Server: if possible, use OFFSET and FETCH instead of JDBC methods #300
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, EclipseLink uses Statement#setMaxRows() to apply a result limit when the target database is MS SQL Server. This is dangerous because mssql-jdbc implements setMaxRows() by executing SET ROWCOUNT, which applies to all queries made on the connection until SET ROWCOUNT is executed again.
Normally, that is not an issue, but it can become a problem if, for example, your query includes a call to a user-defined function that executes another query. When that happens, it creates truly baffling bugs that are very difficult to track down. mssql-jdbc acknowledges that SET ROWCOUNT is not an appropriate way to implement setMaxRows() but currently has no ability to replace it with something better; see microsoft/mssql-jdbc#176.
This PR alters SQLServerPlatform to add the OFFSET and FETCH NEXT clauses to the query, if the version of SQL Server in use supports them. This avoids EclipseLink calling setMaxRows(), and may improve query performance.
This PR is for 2.7. If it looks okay to whoever reviews it, I will open another PR for master.